*Figure 4: Inter-Rater Agreement by Category

********************************************************************************************************************************
************************************PANEL A: Standard Deviation by Category**************************
********************************************************************************************************************************

use "Data_ImportantProvisions_240423.dta", clear

*Standard Deviation across all subsets (stacked bar chart)
gen cat_mod = cat1
replace cat_mod = "Cult_and_Ident" if cat1 == "Culture and Identity"
replace cat_mod = "Intern_Law" if cat1 == "International Law" 
replace cat_mod = "P_and_Symb" if cat1 == "Principles and Symbols"
replace cat_mod = "Regu_and_Over" if cat1 == "Regulation and Oversight"
replace cat_mod = "R_and_D" if cat1 == "Rights and Duties"
replace cat_mod = "Special_Secs" if cat1 == "Special Sections"

levelsof cat_mod, local(unique_categories)

foreach question in "general" "func_democ" "new_democ" "divided_democ"{
// foreach question in "general"{

	foreach category of local unique_categories{
		use "Data_ImportantProvisions_240423.dta", clear
		keep lab cat1 `question'_*_num
		gen cat_mod = cat1
		replace cat_mod = "Cult_and_Ident" if cat1 == "Culture and Identity"
		replace cat_mod = "Intern_Law" if cat1 == "International Law" 
		replace cat_mod = "P_and_Symb" if cat1 == "Principles and Symbols"
		replace cat_mod = "Regu_and_Over" if cat1 == "Regulation and Oversight"
		replace cat_mod = "R_and_D" if cat1 == "Rights and Duties"
		replace cat_mod = "Special_Secs" if cat1 == "Special Sections"
		
		keep if cat_mod == "`category'" 

		egen std = rowsd(*_num)
		keep if std != . 
		keep cat1 std	
		
		egen m_std_`category' = mean(std)
		
		duplicates drop m_std_`category', force
		
		tempfile `category'_`question'
		save `category'_`question', replace

	}

	use "Data_ImportantProvisions_240423.dta", clear
	keep lab cat1 `question'_*_num
	duplicates drop cat1, force
	gen cat_mod = cat1
	replace cat_mod = "Cult_and_Ident" if cat1 == "Culture and Identity"
	replace cat_mod = "Intern_Law" if cat1 == "International Law" 
	replace cat_mod = "P_and_Symb" if cat1 == "Principles and Symbols"
	replace cat_mod = "Regu_and_Over" if cat1 == "Regulation and Oversight"
	replace cat_mod = "R_and_D" if cat1 == "Rights and Duties"
	replace cat_mod = "Special_Secs" if cat1 == "Special Sections"

	levelsof cat_mod, local(unique_categories)
	foreach category of local unique_categories{
		
		merge 1:1 cat1 using `category'_`question', nogen
	}
	
	
	egen std_`question' = rowtotal(m_std_*)
	keep cat1 std_`question'
	
	
	tempfile `question'
	save `question', replace

}



use general, clear
foreach question in "func_democ" "new_democ" "divided_democ"{
	merge 1:1 cat1 using `question', nogen
	erase `question'.dta
}

gen order3 = .
replace order3 = 1 if cat1 == "Rights and Duties"
replace order3 = 2 if cat1 == "Judiciary"
replace order3 = 3 if cat1 == "Legislature" 
replace order3 = 4 if cat1 == "Executive"
replace order3 = 5 if cat1 == "Principles and Symbols"
replace order3 = 6 if cat1 == "Elections"
replace order3 = 7 if cat1 == "Culture and Identity"
replace order3 = 8 if cat1 == "Regulation and Oversight"
replace order3 = 9 if cat1 == "International Law"
replace order3 = 10 if cat1 == "Federalism" 
replace order3 = 11 if cat1 == "Special Sections" 
replace order3 = 12 if cat1 == "Amendment"

graph hbar std*, over(cat1, sort(order3) label( labsize(small))) ///
ytitle("Mean Standard Deviation", size(vsmall)) ///
bar(1, color(maroon)) bar(2, color(navy)) bar(3, color(forest_green)) bar(4, color(purple)) ///
legend(order(1 "Countries in General" 2 "Functioning Democracies" 3 "New Democracies" 4 "Divided Democracies") pos(6) row(2)) ///
blabel(bar, color(black) position(outside) format(%4.2f) size(tiny)) 
graph export "Figure_4.pdf", replace




use general, clear
foreach category in "Amendment" "Elections" "Executive" "Federalism" "Judiciary" "Legislature" "Cult_and_Ident" "Intern_Law" "P_and_Symb" "Regu_and_Over" "R_and_D" "Special_Secs"{
	foreach question in "general" "func_democ" "new_democ" "divided_democ"{
		erase `category'_`question'.dta
	}
}
erase general.dta

